#include "stdafx.h"

class Base
{
public:
	int f()
	{
		return 1;
	}
	virtual int g(int i = 1)
	{
		return i + 1;
	}
	int g(char c)
	{
		return c;
	}
	Base()
	{
		cout<<"Base"<<endl;
	}
	~Base()
	{
		cout<<"~Base"<<endl;
	}
};
class Derived
	:public Base
{
public:
	int f()
	{
		return 2;
	}
	int g(int i = 2)
	{
		return i + 2;
	}
	Derived()
	{
		cout<<"Derived"<<endl;
	}
	~Derived()
	{
		cout<<"~Derived"<<endl;
	}
};
TEST(virtual, hide)
{
	Base b;
	Derived d;
	Base* pd = new Derived();

	EXPECT_EQ(1, b.f());
	EXPECT_EQ(2, d.f());

	EXPECT_EQ(1, pd->f());//hide
	delete pd;//hide
}

TEST(virtual, override_but_default)
{
	Base b;
	Derived d;
	Base* pd = new Derived();
	EXPECT_EQ(2, b.g());
	EXPECT_EQ(4, d.g());
	
	EXPECT_EQ(3, pd->g());//override not contain the default params
}

TEST(virtual, overload)
{
	Base b1;
	Base b2;
	EXPECT_EQ('2', b1.g('2'));
	EXPECT_EQ(3, b2.g(2));
}